package com.unboundedprime.osgisurveillance.monitor;

import com.beust.jcommander.JCommander;
import com.unboundedprime.osgisurveillance.monitor.ioc.ZeptoIocContainer;
import com.unboundedprime.osgisurveillance.monitor.ioc.ZeptoIocContainer.AmbiguousInterfaceException;
import com.unboundedprime.osgisurveillance.monitor.model.Arguments;
import com.unboundedprime.osgisurveillance.monitor.service.SocketService;
import java.beans.XMLDecoder;
import java.util.logging.Level;
import java.util.logging.Logger;

public class Main implements Runnable {

	/**
	 * Arguments model instance.
	 */
	private final Arguments arguments;

	/**
	 * Constructs a new Main instance.
	 * @param args Command line arguments
	 */
	public Main(Arguments arguments) {
		this.arguments = arguments;
	}

	public static void main(final String[] args) {
		final Arguments arguments = new Arguments();
		final JCommander jCommander = new JCommander(arguments, args);
		final Main main = new Main(arguments);
		main.run();
	}

	public void run() {
		try {
			final ZeptoIocContainer container = new ZeptoIocContainer("/META-INF/context/beans.xml");
			final SocketService serverSocketService = container.getObject(SocketService.class);
			serverSocketService.start();
		} catch (AmbiguousInterfaceException ex) {
			System.err.println("Something went very wrong: " + ex.getMessage());
		}
	}
}
